<%@page import="com.framework.entity.Global"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ page import="com.biz.utils.ConfigUtil" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
    String resoursUrl = ConfigUtil.get("RESOURCES_URL");
%>

<!DOCTYPE html>
<html class="no-js">
<head>
<meta charset="UTF-8">
<title>商户中心</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="format-detection" content="telephone=no">
<meta name="renderer" content="webkit">
<meta http-equiv="Cache-Control" content="no-siteapp" />
<jsp:include page="/jsp/inc.jsp"></jsp:include>

</head>
<body>
<div class="businesstop">
	<div class="businessname">${tBaseBrand.name}</div>
	<div class="businesschange" onclick="javascript:window.location.href='${pageContext.request.contextPath}/merchant/toMerchantLayout.ac'" >切换商户<img src="<%=basePath%>resources/image/icon-change.png" alt="" class="icon-change"></div>
</div>
<div class="bustoscan" onclick="toscanbac();">
	<img src="<%=basePath%>resources/image/icon-scan.png" alt="" class="" >
	<div>扫一扫</div>
</div>
<div id="recordList">
	<%--<div class="scanlist">--%>
		<%--<img src="<%=basePath%>resources/image/TXimg.png" alt="" class="scanTX">--%>
		<%--<div class="scaninfo">--%>
			<%--<div class="flexline info">--%>
				<%--<div class="lineleft scaninfoname">徐子贤</div>--%>
				<%--<div class="lineright textright scaninfogoodsname">美的电饭煲</div>--%>
			<%--</div>--%>
			<%--<div class="flexline info">--%>
				<%--<div class="lineleft scaninfotime">2017-05-31 17:21:05</div>--%>
				<%--<div class="lineright textright scaninforesult"><span class="ok">成功</span></div>--%>
			<%--</div>--%>
		<%--</div>--%>
	<%--</div>--%>
	<%--<div class="scanlist">--%>
		<%--<img src="<%=basePath%>resources/image/TXimg.png" alt="" class="scanTX">--%>
		<%--<div class="scaninfo">--%>
			<%--<div class="flexline info">--%>
				<%--<div class="lineleft scaninfoname">徐子贤</div>--%>
				<%--<div class="lineright textright scaninfogoodsname">美的电饭煲</div>--%>
			<%--</div>--%>
			<%--<div class="flexline info">--%>
				<%--<div class="lineleft scaninfotime">2017-05-31 17:21:05</div>--%>
				<%--<div class="lineright textright scaninforesult"><span class="no">失败</span></div>--%>
			<%--</div>--%>
		<%--</div>--%>
	<%--</div>--%>
</div>
<div id="support"></div>
	<!-- 兑换成功 -->
<span class="scantip"><span id="alertMsg" class="tipok">兑换成功</span></span>
<!-- 兑换失败 -->
<!-- <span class="scantip"><span class="tipno">兑换失败<br/>二维码已失效</span></span> -->

	<script type="text/javascript"
			src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script type="text/javascript">
    var ajaxpath="${pageContext.request.contextPath}";

    loadRecord();
    $(function(){
        var site_url = window.document.location.href;
        $.ajax(
            {
                url : ajaxpath+"/wx_js.ac",
				data :{url:site_url},
                type : 'post',
				dataType : 'json',
				success : function(data){
                    wx.config(
                        {
                            debug : false,
                            appId : data.jsData.appid,
                            timestamp : data.jsData.timestamp,
                            nonceStr : data.jsData.nonceStr,
                            signature : data.jsData.signature,
                            jsApiList: ['checkJsApi',
                                'scanQRCode'
                            ]

                        });
                    wx.ready(function () {
                        wx.error(function(res){
								// config信息验证失败会执行error函数，如签名过期导致验证失败，具体错误信息可以打开config的debug模式查看，也可以在返回的res参数中查看，对于SPA可以在这里更新签名。
//								alert("errorMSG:"+res);
							});
						});
                }
            });
    });

    //加载兑换记录
	function loadRecord()
	{
	    var html = '';
	    $.ajax({
			url:'${pageContext.request.contextPath}/merchant/loadRecord.ac',
			type:'post',
			dataType:'json',
			success:function(data)
			{
			    if(data.length > 0)
			    {
                    for(var i=0; i<data.length; i++){
                        var obj = data[i];
                        html+='<div class="scanlist">'+
								'		<img src="'+obj.path+'" alt="" class="scanTX">'+
								'		<div class="scaninfo">'+
								'			<div class="flexline info">'+
								'				<div class="lineleft scaninfoname">'+obj.personName+'</div>'+
								'				<div class="lineright textright scaninfogoodsname">'+obj.goodsName+'</div>'+
								'			</div>'+
								'			<div class="flexline info">'+
								'				<div class="lineleft scaninfotime">'+obj.confirmTime+'</div>'+
								'				<div class="lineright textright scaninforesult"><span class="ok">成功</span></div>'+
								'			</div>'+
								'		</div>'+
								'	</div>';
					}
                   $("#recordList").html(html);
				}
			}
		});
	}


    function toscanbac(){
        wx.scanQRCode({
            needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
            scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码，默认二者都有
            success: function (res) {
                var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
				if(result.indexOf(',')>-1)
				{
                    result = result.split(',')[1];
				}
				$.ajax({
					url:'${pageContext.request.contextPath}/merchant/merchantDoCharge.ac',
					type:'post',
					data:{code:result},
					dataType:'json',
					success:function(data)
					{
						$("#alertMsg").html(data.msg);
						$(".scantip").show().delay(2000).hide(300);
                        loadRecord();
					}
				})
            }
        });
    }


</script>

</body>
</html>
